package com.ruoyi.crop.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.crop.api.domain.CropType;
import com.ruoyi.crop.api.domain.Farmer;
import com.ruoyi.crop.service.CropService;
import com.ruoyi.crop.service.CropTypeService;
import com.ruoyi.crop.service.FarmerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/cropType")
public class CropTypeController extends BaseController {

    @Autowired
    CropTypeService cropTypeService;


    /**
     * 获取农作物类别列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CropType cropType)
    {
        startPage();
        List<CropType> list = cropTypeService.selectCropTypeList(cropType);
        return getDataTable(list);
    }

    /**
     * 根据农作物类别编号获取详细信息
     */
    @GetMapping(value = "/{cropTypeId}")
    public AjaxResult getInfo(@PathVariable Integer cropTypeId)
    {
        return success(cropTypeService.getById(cropTypeId));
    }

    /**
     * 新增农作物类别
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CropType cropType)
    {
        return toAjax(cropTypeService.saveCropType(cropType));
    }

    /**
     * 修改农作物类别
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CropType cropType)
    {
        return toAjax(cropTypeService.updateCropTypeById(cropType));
    }

    /**
     * 删除农作物类别
     */
    @DeleteMapping("/{cropTypeIds}")
    public AjaxResult remove(@PathVariable Integer[] cropTypeIds)
    {
        return toAjax(cropTypeService.removeBatchByIds(Arrays.asList(cropTypeIds)));
    }
}
